package com.woniuxy.lab.woniu_lab_boss.util;


import com.woniuxy.lab.woniu_lab_boss.common.Shell;
import lombok.Data;

@Data
public class ShellUtil {

    private Shell shell;

    public ShellUtil() {
    }

    public ShellUtil(String host, String username, String password) {
        this.shell = new Shell(host, username, password);
    }

    public static ShellUtil getShell(String host, String username, String password) {
        return new ShellUtil(host, username, password);
    }

    // ----------------------

    public String run(String cmd) {
        return shell.execCommand(cmd);
    }

    public String cp(String oldFile, String newFile){
        return shell.execCommand("cp "+oldFile+" "+newFile);
    }

    public String mv(String oldFile, String newFile){
        return shell.execCommand("mv "+oldFile+" "+newFile);
    }

    public String ls(String path){
        return shell.execCommand(path);
    }

    public String mkdir(String dir){
        return shell.execCommand("mkdir "+dir);
    }

    public String touch(String file){
        return shell.execCommand("touch "+file);
    }

    public String ps(String keyWord){
        return shell.execCommand("ps aux | grep "+keyWord);
    }

    public String cpr(String oldFile, String newFile){

        return shell.execCommand("cp -r "+oldFile+" "+newFile);
    }
    public String cpry(String oldFile, String newFile){

        return shell.execCommand("cp -ry "+oldFile+" "+newFile);
    }

    public void startCompose() {
        shell.execCommand("cd ~/temp/range01 && docker-compose up -d");
    }
}
